<template>
  <transition name="toast">
    <div v-if="visible" class="toast-container">
      <i :class="iconClass" v-if="icon"></i>
      <span>{{ message }}</span>
    </div>
  </transition>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      message: '',
      type: 'info'
    }
  },

  computed: {
    iconClass() {
      return {
        'success': 'icon-check',
        'error': 'icon-close',
        'warning': 'icon-warning'
      }[this.type]
    }
  },

  methods: {
    show(message, type = 'info', duration = 3000) {
      this.message = message
      this.type = type
      this.visible = true
      
      setTimeout(() => {
        this.visible = false
      }, duration)
    }
  }
}
</script>

<style scoped lang="scss">
.toast-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 12px 24px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border-radius: 4px;
  display: flex;
  align-items: center;
  z-index: 9999;

  i {
    margin-right: 8px;
    font-size: 16px;
  }
}

.toast-enter-active, .toast-leave-active {
  transition: opacity 0.3s;
}
.toast-enter, .toast-leave-to {
  opacity: 0;
}
</style>